#define _CRT_SECURE_NO_WARNINGS 1
struct ListNode* getIntersectionNode(struct ListNode* headA, struct ListNode* headB) {
    struct ListNode* tailA = headA;
    struct ListNode* tailB = headB;

    int lenA = 1;
    int lenB = 1;
    while (tailA->next)
    {
        tailA = tailA->next;
        lenA++;
    }
    while (tailB->next)
    {
        tailB = tailB->next;
        lenB++;
    }

    int k = abs(lenA - lenB);
    struct ListNode* shorthead = headA;
    struct ListNode* longhead = headB;
    if (lenA > lenB)
    {
        longhead = headA;
        shorthead = headB;
    }

    while (k--)
    {
        longhead = longhead->next;
    }

    while (shorthead)
    {
        if (shorthead == longhead)
            return shorthead;
        shorthead = shorthead->next;
        longhead = longhead->next;
    }
    return NULL;
}